/**
 * Class:SelectCommentAction Class
 * Description:This ACtionClass used for retrieval of comments of a particular post
 */

package com.actions;

import com.DAO.CategoryDAO;
import com.DAO.CommentDAO;
import com.DAO.NoticeDAO;
import com.beans.CategoryForm;
import com.beans.CommentForm;
import com.beans.NoticeForm;

import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class SelectCategoryAction extends Action {
	private final static String SUCCESS = "success";

	/**
	 * This is the action called from the Struts framework.
	 * 
	 * @param mapping
	 *            The ActionMapping used to select this instance.
	 * @param form
	 *            The optional ActionForm bean for this request.
	 * @param request
	 *            The HTTP Request we are processing.
	 * @param response
	 *            The HTTP Response we are processing.
	 * @throws java.lang.Exception
	 * @return
	 */
	
	@SuppressWarnings("finally")
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		int categoryId=2;
		
		if(request.getParameter("id")!=null){
			try{
					categoryId=Integer.parseInt(request.getParameter("id"));
			}
			catch(Exception e){
				System.out.println("Id not valid");
				
			}
		}
		CategoryDAO catDAO=new CategoryDAO();
		HttpSession session=request.getSession();
		
		CategoryForm categoryForm=catDAO.getCategoryInfo(categoryId);
		NoticeDAO noticeDAO=new NoticeDAO();
		
		//setting category id
		
		session.setAttribute("id",categoryId);
				
		// if Request is Birthday page
		
		if(categoryId==2){
			return mapping.findForward("birthday");
		}
		
		return mapping.findForward("success");
				
	}
}
